//这个类用来设定邮件的内容，设定一个点击就可以获取一个验证码
package common.util.mail;
	
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ncp.model.entity.registerlogin.UserBasicBean;
	
@SuppressWarnings("serial")
public class SendCodeServlet extends HttpServlet {
		public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
				response.setContentType("text/html");
				response.setCharacterEncoding("UTF-8");
				String msg = "";
				PrintWriter out = response.getWriter();
				HttpSession session = request.getSession(true);
				String toAddress = request.getParameter("userEmail");
				session.setAttribute("toAddress", toAddress);
				randcode Rcode = new randcode();
				String CheckCode=Rcode.randomString(6);
				MailSenderInfo mailInfo = new MailSenderInfo();
				mailInfo.setMailServerHost("smtp.126.com");
				mailInfo.setMailServerPort("25");
				mailInfo.setValidate(true);
				mailInfo.setUserName("nongchanpinxm@126.com");
				mailInfo.setPassWord("2012904");//您的邮箱密码　　　 
				mailInfo.setFromAddress("nongchanpinxm@126.com");
				mailInfo.setToAddress(toAddress);
				mailInfo.setSubject("农产品项目组");
				String content="亲爱的用户：<p><br>您的验证码是"
					+CheckCode+"，请在刚才所在的页面输入该验证码，点击“下一步”进行新密码的重置，感谢您的使用！";
				mailInfo.setContent(content);		 			
				//这个类主要来发送邮件
				SimpleMailSender sms = new SimpleMailSender();
				sms.sendTextMail(mailInfo);//发送文本格式的邮件
				//sms.sendHtmlMail(mailInfo);//发送html格式的邮件
				request.getRequestDispatcher("pages/registerlogin/mailcheckcode.jsp").forward(request, response);
				String checkcode = request.getParameter("ckcode");
				if(checkcode==CheckCode){
					msg="true";
				}
				else{
					msg="false";
				}out.print(msg);
		}
		   
		
		  public void doPost(HttpServletRequest request, HttpServletResponse response)
		  throws ServletException, IOException {
	            response.setContentType("text/html");
	            this.doGet(request, response);
        }
}